package com.netease.pris.activity;

import android.app.AlertDialog.Builder;
import android.app.Dialog;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.os.Message;
import android.os.StatFs;
import android.text.TextUtils;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.LinearLayout.LayoutParams;
import android.widget.ProgressBar;
import android.widget.RemoteViews;
import android.widget.TextView;
import android.widget.Toast;
import com.netease.framework.ActivityEx;
import com.netease.g.b;
import com.netease.pris.a.i;
import com.netease.update.ProgressInfo;
import com.netease.update.c;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;

public class PRISActivityUpdate extends ActivityEx
  implements View.OnClickListener
{
  private static String a = "UpdateConfirm";
  private static boolean b = false;
  private static boolean c = false;
  private static final int h = 0;
  private static final int l = -1;
  private static final int m = 1;
  private static final int n = 2;
  private static final int o = 3;
  private static final int p = 4;
  private static final int q = 5;
  private Handler A = new fb(this);
  private Button d;
  private Button e;
  private Bundle f;
  private String g;
  private ProgressDialog i;
  private boolean j = false;
  private Thread k;
  private String r = null;
  private ProgressInfo s = null;
  private Context t = null;
  private NotificationManager u = null;
  private View v;
  private TextView w;
  private ProgressBar x;
  private View y;
  private TextView z;

  private void a(int paramInt1, int paramInt2)
  {
    Message localMessage = this.A.obtainMessage(2, paramInt1, paramInt2);
    this.A.sendMessage(localMessage);
  }

  private void a(ProgressInfo paramProgressInfo)
  {
    boolean bool = true;
    Notification localNotification = new Notification();
    localNotification.icon = 17301633;
    localNotification.flags = (0x2 | localNotification.flags);
    Object[] arrayOfObject = new Object[bool];
    arrayOfObject[0] = this.t.getText(2131361792);
    localNotification.tickerText = getString(2131362187, arrayOfObject);
    RemoteViews localRemoteViews = new RemoteViews(getPackageName(), 2130903069);
    localRemoteViews.setTextViewText(2131558424, this.t.getText(2131361792));
    int i1 = paramProgressInfo.c();
    int i2 = paramProgressInfo.b();
    if (paramProgressInfo.c() == -1);
    while (true)
    {
      localRemoteViews.setProgressBar(2131558494, i1, i2, bool);
      localRemoteViews.setTextViewText(2131558491, paramProgressInfo.d());
      localRemoteViews.setImageViewResource(2131558490, 2130837670);
      localNotification.contentView = localRemoteViews;
      Intent localIntent = new Intent();
      localIntent.setClass(this.t, PRISActivityUpdate.class);
      localNotification.contentIntent = PendingIntent.getBroadcast(this.t, 0, localIntent, 0);
      this.u.notify((int)paramProgressInfo.e(), localNotification);
      return;
      bool = false;
    }
  }

  private void a(String paramString1, String paramString2, String paramString3, long paramLong1, long paramLong2)
  {
    this.k = new da(this, paramString1, paramString2, paramString3, paramLong1, paramLong2);
    this.k.start();
  }

  private boolean a(long paramLong)
  {
    StatFs localStatFs = new StatFs(new File(Environment.getExternalStorageDirectory().getPath()).getPath());
    if (localStatFs.getBlockSize() * (-8 + localStatFs.getAvailableBlocks()) > paramLong);
    for (int i1 = 1; ; i1 = 0)
      return i1;
  }

  private boolean b(String paramString1, String paramString2)
  {
    int i1 = 0;
    if ((TextUtils.isEmpty(paramString1)) || (paramString2 == null));
    while (true)
    {
      return i1;
      File localFile = new File(paramString1);
      try
      {
        FileInputStream localFileInputStream = new FileInputStream(localFile);
        String str = c.a(c.a(localFileInputStream));
        if (b)
          b.e(a, "computed-md5==" + str);
        if (str.equals(paramString2))
          i1 = 1;
        try
        {
          localFileInputStream.close();
        }
        catch (IOException localIOException)
        {
          b.f(a, "failed to close file input stream of file " + paramString1);
          localIOException.printStackTrace();
        }
      }
      catch (FileNotFoundException localFileNotFoundException)
      {
        b.e(a, "file not exist at " + paramString1);
      }
    }
  }

  private void e()
  {
    f();
    this.j = false;
    this.e.setEnabled(true);
  }

  private void f()
  {
    if (this.k != null)
      this.k.interrupt();
  }

  private void g()
  {
    setContentView(this.v, new LinearLayout.LayoutParams(-1, -2));
  }

  private void h()
  {
    if (this.g == null)
    {
      Toast.makeText(this, 2131362007, 1).show();
      finish();
    }
    if (!new File(this.g).exists())
    {
      Toast.makeText(this, 2131362007, 1).show();
      finish();
    }
    Uri localUri = Uri.parse("file://" + this.g);
    Intent localIntent = new Intent("android.intent.action.VIEW", localUri);
    localIntent.setDataAndType(localUri, "application/vnd.android.package-archive");
    localIntent.setClassName("com.android.packageinstaller", "com.android.packageinstaller.PackageInstallerActivity");
    startActivity(localIntent);
    finish();
  }

  private void i(int paramInt)
  {
    if (this.i != null)
      this.i.setMessage(getResources().getText(paramInt));
  }

  private void j(int paramInt)
  {
    this.z.setText(2131362110);
    setContentView(this.y, new LinearLayout.LayoutParams(-1, -2));
  }

  private Dialog k(int paramInt)
  {
    AlertDialog.Builder localBuilder = new AlertDialog.Builder(this);
    localBuilder.setMessage(getResources().getText(paramInt)).setPositiveButton(getResources().getText(17039379), new ey(this));
    return localBuilder.create();
  }

  private void l(int paramInt)
  {
    Message localMessage = this.A.obtainMessage(2, paramInt, -1);
    this.A.sendMessage(localMessage);
    if (b)
      b.e(a, "send message to handler to update download dialog, count == " + paramInt);
  }

  private void r()
  {
    this.f = getIntent().getExtras();
    if ((this.f == null) || (!this.f.containsKey("location")) || (!this.f.containsKey("size")) || (!this.f.containsKey("name")) || (!this.f.containsKey("md5")) || (!this.f.containsKey("version")))
    {
      Toast.makeText(this, 2131362000, 1).show();
      finish();
    }
    String str1 = this.f.getString("name");
    this.r = str1;
    if (b)
      b.e(a, "getData: pkgName == " + str1);
    File localFile = new File(c.l);
    if (localFile == null)
      showDialog(2131361998);
    while (true)
    {
      return;
      String str2 = localFile.getPath();
      this.g = (str2 + "/" + "download" + "/" + str1);
      if (b)
        b.e(a, "packagePath==" + this.g);
      if (this.g.matches(".*\\.apk"))
        continue;
      this.g += ".apk";
    }
  }

  private void s()
  {
    if (this.f == null);
    while (true)
    {
      return;
      StringBuilder localStringBuilder = new StringBuilder();
      localStringBuilder.append("\n");
      localStringBuilder.append(getText(2131362014));
      localStringBuilder.append("\n\n");
      localStringBuilder.append(getText(2131362015));
      localStringBuilder.append("\n");
      localStringBuilder.append(this.f.getString("version"));
      localStringBuilder.append("\n\n");
      localStringBuilder.append(getText(2131362016));
      localStringBuilder.append("  ");
      localStringBuilder.append(i.b(Long.valueOf(this.f.getString("size")).longValue()));
      if (this.f.containsKey("function"))
      {
        ArrayList localArrayList3 = this.f.getStringArrayList("function");
        if ((localArrayList3 != null) && (localArrayList3.size() > 0))
        {
          localStringBuilder.append("\n\n");
          localStringBuilder.append(getText(2131362017));
          Iterator localIterator3 = localArrayList3.iterator();
          while (localIterator3.hasNext())
          {
            String str3 = (String)localIterator3.next();
            localStringBuilder.append("\n");
            localStringBuilder.append(str3);
          }
        }
      }
      if (this.f.containsKey("bugfix"))
      {
        ArrayList localArrayList2 = this.f.getStringArrayList("bugfix");
        if ((localArrayList2 != null) && (localArrayList2.size() > 0))
        {
          localStringBuilder.append("\n\n");
          localStringBuilder.append(getText(2131362018));
          Iterator localIterator2 = localArrayList2.iterator();
          while (localIterator2.hasNext())
          {
            String str2 = (String)localIterator2.next();
            localStringBuilder.append("\n");
            localStringBuilder.append(str2);
          }
        }
      }
      if (this.f.containsKey("others"))
      {
        ArrayList localArrayList1 = this.f.getStringArrayList("others");
        if ((localArrayList1 != null) && (localArrayList1.size() > 0))
        {
          localStringBuilder.append("\n\n");
          localStringBuilder.append(getText(2131362019));
          Iterator localIterator1 = localArrayList1.iterator();
          while (localIterator1.hasNext())
          {
            String str1 = (String)localIterator1.next();
            localStringBuilder.append("\n");
            localStringBuilder.append(str1);
          }
        }
      }
      ((TextView)findViewById(2131558712)).setText(localStringBuilder.toString());
    }
  }

  private void t()
  {
    this.e = ((Button)findViewById(2131558714));
    this.e.setOnClickListener(this);
    this.d = ((Button)findViewById(2131558713));
    this.d.setOnClickListener(this);
    this.v = LayoutInflater.from(this).inflate(2130903115, null, false);
    this.w = ((TextView)this.v.findViewById(2131558677));
    this.x = ((ProgressBar)this.v.findViewById(2131558678));
    this.y = LayoutInflater.from(this).inflate(2130903114, null, false);
    this.z = ((TextView)this.y.findViewById(2131558675));
  }

  private void u()
  {
    if (this.j);
    while (true)
    {
      return;
      if (!Environment.getExternalStorageState().equals("mounted"))
      {
        showDialog(2131361998);
        continue;
      }
      if (!c.a(this))
      {
        showDialog(2131362012);
        continue;
      }
      if (this.e != null)
        this.e.setEnabled(false);
      this.j = true;
      w();
    }
  }

  private void v()
  {
    String str1 = this.f.getString("location");
    String str2 = this.f.getString("size");
    if (!TextUtils.isEmpty(this.g))
    {
      File localFile = new File(this.g);
      long l1;
      if (localFile.length() >= Long.valueOf(str2).longValue())
      {
        localFile.delete();
        l1 = 0L;
      }
      while (true)
      {
        if (b)
          b.e(a, "be about to update. Size of package to download is: " + str2 + ", old packet size is: " + l1);
        a(str1, this.g, this.f.getString("md5"), l1, Long.valueOf(str2).longValue());
        while (true)
        {
          return;
          if (a(Long.valueOf(str2).longValue() - localFile.length()))
            break;
          showDialog(2131362002);
        }
        l1 = localFile.length();
      }
    }
    throw new RuntimeException("packagePath is null or empty when calling onUpdate()!");
  }

  private void w()
  {
    if (b)
      b.e(a, "checkExist: packagePath == " + this.g);
    this.A.post(new ex(this));
  }

  private void x()
  {
    if (!TextUtils.isEmpty(this.g))
      new File(this.g).delete();
  }

  private void y()
  {
    String str = this.f.getString("version");
    if (!TextUtils.isEmpty(str))
    {
      int i1 = str.indexOf(" ");
      if (i1 > 0)
        str = str.substring(0, i1);
    }
    c.a(str, null, this);
  }

  protected void a(int paramInt)
  {
    if (paramInt > 0)
    {
      this.w.setText(paramInt + "%");
      this.x.setProgress(paramInt);
    }
  }

  protected void b(int paramInt)
  {
    if ((paramInt > 0) && (this.i != null))
    {
      this.i.setProgress(paramInt);
      if (b)
        b.e(a, "set download dialog progress, count == " + paramInt);
    }
  }

  public void onClick(View paramView)
  {
    switch (paramView.getId())
    {
    default:
    case 2131558713:
    case 2131558714:
    }
    while (true)
    {
      return;
      u();
      continue;
      finish();
    }
  }

  protected void onCreate(Bundle paramBundle)
  {
    super.onCreate(paramBundle);
    setContentView(2130903122);
    d(2130837642);
    setTitle(2131362108);
    t();
    r();
    s();
    this.t = this;
    this.u = ((NotificationManager)this.t.getSystemService("notification"));
  }

  public Dialog onCreateDialog(int paramInt)
  {
    Object localObject;
    switch (paramInt)
    {
    default:
      localObject = null;
    case 1:
    case 2131361998:
    case 2131362001:
    case 2131362002:
    case 2131362005:
    case 2131362006:
    case 2131362012:
    case 2131362013:
    case 2131362021:
    case 2131362023:
    }
    while (true)
    {
      return localObject;
      this.i = new fa(this, this);
      this.i.setProgressStyle(1);
      this.i.setMessage(getText(2131362022));
      this.i.setButton(-2, getResources().getText(2131361995), new ez(this));
      localObject = this.i;
      continue;
      localObject = k(paramInt);
    }
  }

  public boolean onKeyDown(int paramInt, KeyEvent paramKeyEvent)
  {
    if ((this.j) && (4 == paramInt))
      f();
    return super.onKeyDown(paramInt, paramKeyEvent);
  }

  public void onPrepareDialog(int paramInt, Dialog paramDialog)
  {
    switch (paramInt)
    {
    default:
      super.onPrepareDialog(paramInt, paramDialog);
    case 1:
    }
    while (true)
    {
      return;
      this.i = ((ProgressDialog)paramDialog);
      this.i.setMessage(getText(2131362022));
    }
  }
}

/* Location:           D:\android\hack\dex2jar-0.0.9.8\classes_dex2jar.jar
 * Qualified Name:     com.netease.pris.activity.PRISActivityUpdate
 * JD-Core Version:    0.6.0
 */